package com.sansan.qiangji.controller.wage;

import com.sansan.qiangji.enums.ResultEnum;
import com.sansan.qiangji.exception.ServiceException;

import com.sansan.qiangji.form.wage.PickingStockWageAddForm;
import com.sansan.qiangji.form.wage.PickingStockWageEditForm;
import com.sansan.qiangji.form.wage.PickingStockWageListForm;
import com.sansan.qiangji.realize.wage.PickingStockWageReal;
import com.sansan.qiangji.resultVO.ResultVO;
import com.sansan.qiangji.utils.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/pickingStockWage")
@CrossOrigin()
public class PickingStockWageController {
    @Autowired
    private PickingStockWageReal pickingStockWageReal;


    @PostMapping("/addPickingStockWage")
    public ResultVO<Object> addPickingStockWage(@Valid @RequestBody PickingStockWageAddForm pickingStockWageAddForm, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            log.error("【拣货单新增】参数不正确，pickingStockWageAddForm={}",pickingStockWageAddForm);
            throw new ServiceException(ResultEnum.PARAM_ERROR);
        }
        pickingStockWageReal.addPickingStockWage(pickingStockWageAddForm);
        return ResultVOUtil.success(null);
    }


    @PostMapping("/getPickingStockWageList")
    public ResultVO<Object> getPickingStockWageList(@Valid @RequestBody PickingStockWageListForm form, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            log.error("【拣货单查询】参数不正确，pickingStockWageAddForm={}",form);
            throw new ServiceException(ResultEnum.PARAM_ERROR);
        }
        return ResultVOUtil.success(pickingStockWageReal.pickingStockWageList(form));
    }


    @PostMapping("/editPickingStockWage")
    public ResultVO<Object> editPickingStockWage(@Valid @RequestBody PickingStockWageEditForm pickingStockWageEditForm, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            log.error("【拣货单修改】参数不正确，pickingStockWageAddForm={}",pickingStockWageEditForm);
            throw new ServiceException(ResultEnum.PARAM_ERROR);
        }
        pickingStockWageReal.editPickingStockWage(pickingStockWageEditForm);
        return ResultVOUtil.success(null);
    }


    @PostMapping("/deletePickingStockWage")
    public ResultVO<Object> deletePickingStockWage(@RequestParam(value = "pickingStockWageId") Integer pickingStockWageId){
        pickingStockWageReal.deletePickingStockWage(pickingStockWageId);
        return ResultVOUtil.success(null);
    }
}
